<?php
declare(strict_types = 1);

use Phinx\Db\Table\Index;
use Phinx\Migration\AbstractMigration;

final class UserFavoritesTable extends AbstractMigration
{
	public function up()
	{
		$table = $this->table(
			'user_favorites', [
				'id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '用户收藏表',
			]
		);
		$table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID']);
		$table->addColumn(
			'user_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => 'user_id']
		);
		$table->addColumn('link_type', 'enum', ['values' => 'folder,file', 'default' => 'folder', 'comment' => '收藏类型folder=>文件夹,file=>文件']);
		$table->addColumn(
			'collection_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '收藏id']
		);
		$table->addColumn(
			'create_time', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => null, 'comment' => '创建时间']
		);
		$table->addColumn(
			'update_time', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => null, 'comment' => '更新时间']
		);
		$table->addIndex(['user_id', 'collection_id', 'link_type'], ['name' => 'idx_user_collection', 'unique' => true]);
		$table->save();
	}

	public function down()
	{
		$this->table('user_favorites')->drop()->save();
	}
}
